package com.fintech.third.task;

import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.fintech.third.dao.MoxieMessageMapper;
import com.fintech.third.model.moxie.MoXieTaskType;
import com.fintech.third.service.moxie.MoXieService;
import com.marvels.common.utils.MarvelsLogUtil;

/**
 * 定时查询魔蝎运营商  支付宝message
 * @author tangpw
 *
 */
@Configuration
@EnableScheduling
public class MoxieMessageTask {
	
	@Autowired(required = true)
	private MoXieService MoXie;
	
	@Autowired
	private MoxieMessageMapper moxieMessageMapper;
	
	@Scheduled(cron="0 0/5 *  * * ? ")
	public void moxieMessageTask(){
		MarvelsLogUtil.getInstance().info(">>>>>>>>>定时查询魔蝎运营商,支付宝message开始");
		List<Map<String, Object>> list=moxieMessageMapper.selectList();
		if(CollectionUtils.isNotEmpty(list)){//list不为空
			for(Map<String, Object> map:list){
				String loanId=map.get("loanId").toString();
				int moXieTaskType=Integer.parseInt(map.get("moXieTaskType").toString());
				MarvelsLogUtil.getInstance().info(">>>>>>>>>loanId"+loanId+",moXieTaskType"+moXieTaskType+",开始查询message");
				if(moXieTaskType==MoXieTaskType.ALIPAY.getType()){
					MoXie.getReportMessage(loanId,MoXieTaskType.ALIPAY);
				}else if(moXieTaskType==MoXieTaskType.CARRIER.getType()){
					MoXie.getReportMessage(loanId,MoXieTaskType.ALIPAY);
				}else{
					MarvelsLogUtil.getInstance().info(">>>>>>>>>loanId"+loanId+",moXieTaskType"+moXieTaskType+"类型错误");
				}
			}
			
		}
		MarvelsLogUtil.getInstance().info(">>>>>>>>> 定时查询魔蝎运营商,支付宝message结束");
		
	}
}
